<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.net.URLDecoder,cn.edu.nju.ws.sview.Config,cn.edu.nju.ws.sview.views.Comment,cn.edu.nju.ws.sview.views.Image,cn.edu.nju.ws.sview.views.Group,cn.edu.nju.ws.sview.util.URIUtil,java.net.URLEncoder,java.util.Enumeration,java.util.ArrayList,cn.edu.nju.ws.sview.util.URIUtil,cn.edu.nju.ws.sview.views.Entity,cn.edu.nju.ws.sview.views.data.EntityManagement,cn.edu.nju.ws.sview.views.data.EntityManagement.URIMember,cn.edu.nju.ws.sview.cache.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SView Identity</title>
<link rel="icon" href="/sview/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/sview/css/layout.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/smoothness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/views/identity.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/easyui.css" />
<script type="text/javascript" src="/sview/script/jquery.js"></script>
<script type="text/javascript" src="/sview/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/sview/script/jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="/sview/script/global.js"></script>
<script type="text/javascript" src="/sview/script/views/identity_collection.js"></script>
</head>
<body>
<%
	String lang = request.getParameter("lang");
	if (lang != null && lang.equals("zh")) {
		request.getRequestDispatcher("construct_collection_zh.jsp")
				.forward(request, response);
		return;
	} else if (lang == null) {
		lang = "en";
	}

	String genre = request.getParameter("genre");
	String eidStr = request.getParameter("eid");
	String curmemcidStr = request.getParameter("curmemcid");
	int eid = 0;
	int etype = 0;
	int curmemcid = 0;
	if (genre == null || curmemcidStr == null) {
		String location = "../views/index.jsp";
		if (lang.equals("zh"))
			location = location + "?lang=" + lang;
		response.sendRedirect(location);
		return;
	} else {
		eid = Integer.parseInt(eidStr);
		curmemcid = Integer.valueOf(curmemcidStr);
	}

	etype = Entity.COLLECTION;

	String testName = Entity.getNameByEntityID(eid, "en");
	if (testName == null) {
		String location = "eerror.jsp";
		if (lang.equals("zh"))
			location = location + "?lang=" + lang;
		response.sendRedirect(location);
		return;
	}

	String gname = null;
	if (session.getAttribute("groupName") != null) {
		gname = (String) session.getAttribute("groupName");
	} else {
		String location = "../views/index.jsp";
		if (lang.equals("zh"))
			location = location + "?lang=" + lang;
		response.sendRedirect(location);
		return;
	}

	int gid = Group.getGroupIdByName(gname);

	String ename = request.getParameter("n");
	if (ename != null) {
		ename = URLDecoder.decode(ename, "utf-8");
	}
%>
<jsp:include page="/vheader.jsp" flush="true">
   <jsp:param name="f" value="e"/>
</jsp:include>
<div class="container">
   <div class="top">
      <div class="mspacing"></div>
      <%
      	if (!Entity.isTmpCollection(etype, eid)) {
      %>
      <div class="operation">Edit Custom Collection</div>
      <%
      	} else {
      %>
       <div class="operation">Create Custom Collection</div>
      <%
      	}
      %>
      <div class="edit-save"> 
         <input type="button" value="Save" class="sbutton btn btn-primary fb">
         <input type="button" value="Cancel" class="cbutton btn fb">
       </div>
   </div>
   <div class="mspacingLittle"></div>
      <div class="main">
	     <div class="entityName section">
	     	<div class="tab-header">
	           <div class="tab" >
			       <span class="title">Basic Information</span>
			       <span class="tab-status"></span>
			    </div>
	        </div>
			<div class="content">
			    <div class='namebox'>
                   <span class="label">Name:</span>
                   <span>
                      <%
                      	if (ename == null) {
                      		ename = Entity.getNameByEntityID(eid, "en");
                      	}
                      %>
                            <input type="text" class="ftext inename" value="<%=ename%>" >
                   </span>
                 </div>
               
                 <div class='descbox'>
                    <span class="label">Description:</span>
                    <span>
                    <%
                    	String comment = null;
                    	Comment commObj = Comment.getCommentByMemberLangGroup(etype, eid,
                    			lang, gname);
                    	if (commObj != null) {
                    		comment = commObj.getText();
                    	}
                    %>
                    <%
                    	if (comment != null && !comment.trim().equals("")) {
                    %>
                    	<textarea class="ftext commentarea "><%=comment%></textarea>
                    <%
                    	} else {
                    %>
                     	<textarea class="ftext commentarea "></textarea>
                    <%
                    	}
                    %>
                    </span>
                </div>
             </div>
		 </div>
	     <div class="identity section">
		    <div class="tab-header">
	           <div class="tab" >
			       <span class="title">Members </span>
			        <span class="tab-status"></span>
			    </div>
	        </div>
			<div class="content">
				<div class="leftPanel">
					<div class="entity-list">
					</div>
					<div class="advancedBox">
					    <a  href="javascript:void(0)" class="advancedSwitch">Add URI manually</a>
					    <div class="content">
					    	<div class='header'>Enter a uri to use as member:</div>
					    	<div><input id="uriAdded" type="text" size="75" value="http://"  class ="ftext"></div>
					    	<div class="opBox">
					    	<input type="button" value="Ok" class="addbtn" id="addbtn" />
					    	<input type="button" value="Reset" class="rstbtn" id="rstbtn" />
					    	</div>
					       <div class="input-status">
					    	  <div class="wait sts">
					    		  <div class="hint"><span>Checking...</span></div>
					    	  </div>
					    	  <div class="valid sts"></div>
					    	  <div class="invalid sts"><img src="/sview/icons/warning.png"></img>Sorry, SView did not find RDF description about the uri.</div>
					       </div>					    	
					    </div>
					</div>
				</div>
				<div class='rightPanel'>
				   <div class="recommendSection">
			        <ul>
		               <li><a href="#tabs-search">Falcons Search</a></li>
		               <li><a href="#tabs-removed">Removed</a></li>
	                </ul>
                    <div id="tabs-search">
                        <div class="searchBox">
                            <input id="query" type="text" size="75" value=""  class ="ftext" name="query">
         	                <input type="button" value="Search" class="sbtn" id="searchq">
                        </div>                    
	                  	<div class="content">
	                  	   <ul class="entityList"></ul>
	                  	</div>
	                 </div>	                 
	                <div id="tabs-removed">
	                  	<div class="content">
	                  	   <ul class="entityList"></ul>
	                  	</div>
	                 </div>
				    </div>
				   </div>
			</div>
		 </div>	 
	   </div>
</div>
<input type="hidden" id="gid" value="<%=gid%>" />
<input type="hidden" id="gname" value="<%=gname%>" />
<%
		if (ename != null) {
	%>
<input type="hidden" id="ename" value="<%=ename%>" />
<%
	}
%>
<input type="hidden" id="display-lang" value="en" />
<input type="hidden" id="genre" value="<%=genre%>" />
<input type="hidden" id="curmemcid" value="<%=curmemcid%>" />
<%
	if (!Entity.isTmpCollection(etype,eid)) {
%>
<input type="hidden" id="custom_type" value="edit" />
<%
	} else {
%>
<input type="hidden" id="custom_type" value="create" />
<%
	}
%>
<input type="hidden" id="etype" value="<%=etype%>" />
<input type="hidden" id="eid" value="<%=eid%>" />
<jsp:include page="/vfooter.jsp"></jsp:include>
</body>
</html>